package com.ming.rabbitmq.consumer.topic;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Main1 {
    public static void main(String[] args) throws IOException, TimeoutException {
        //1.创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("119.91.238.104");
        factory.setPort(5672);
        factory.setVirtualHost("/topic");
        factory.setUsername("admin");
        factory.setPassword("admin");
        //3. 创建连接 Connection
        Connection connection = factory.newConnection();
        //4. 创建Channel
        Channel channel = connection.createChannel();

        String queue1Name = "topic_name1";
        String queue2Name = "topic_name2";
//        channel.queueDeclare("work_queue",true,false,false,null);
        DefaultConsumer consumer = new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.printf("message:%s\n", new String(body));
            }
        };
        channel.basicConsume(queue1Name,true,consumer);
    }
}
